package com.caigou.comm.base.ext

/**
 * @author #Suyghur.
 * Created on 2021/09/16
 */
sealed class Resource<T>(val data: T? = null, val errorCode: Int = 0, val errorMsg: String = "") {
    class Success<T>(data: T) : Resource<T>(data)
    class Loading<T>(data: T? = null) : Resource<T>(data)
    class DataError<T>(errorCode: Int, errorMsg: String) : Resource<T>(null, errorCode, errorMsg)

    override fun toString(): String {
        return when (this) {
            is Success<*> -> "Success[data=$data]"
            is Loading<T> -> "Loading"
            is DataError -> "Error[exception=$errorCode $errorMsg]"
        }
    }
}